// other/chooserole/chooserole.js
const app = getApp()
import { HTTP } from '../../utils/https.js'
let http = new HTTP()
var util = require('../../utils/util.js');
Page({

  /**
   * 页面的初始数据
   */
  data: {
    curindex:0,
    checkid:Number
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    this.setData({
      checkid:options.id
    })
  },
  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },
 //角色分类点击
  chooserole(e){
    this.setData({
      curindex: e.currentTarget.dataset.index
    })
  },
  //跳转填写信息页面
    goinformation(){
      if(this.data.curindex == 0){
        wx.showToast({
          title: '选择身份！',
          icon: 'none',
          duration: 2000
        });
        return;
      }
      var that = this;
          const data = { identity:this.data.curindex == 1 ? 'staff' : 'boss'};
          http.request({
            url: 'mini/v1/personal/identity_switch',
            methods:'post',
            data: data,
            success: function (res) {
              wx.setStorageSync('token', res.data.user.auth.token_type + '' + res.data.user.auth.access_token);
              wx.removeStorageSync('checkrole');
              wx.removeStorageSync('user_id');
              wx.removeStorageSync('checklogin');
              wx.removeStorageSync('headimgurl');
              wx.setStorageSync('checklogin', 'checklogin');
              wx.setStorageSync('dataindex', 'dataindex');
              wx.setStorageSync('user_id', res.data.user.user_id);
              wx.setStorageSync('headimgurl', res.data.user.headimgurl);
              wx.setStorageSync('checkrole', data.identity);
              
              if(res.data.user.is_make == 1){
                wx.navigateTo({ 
                  url: "../information/information?check="+that.data.curindex 
                });
                return false
              }
              
              wx.switchTab({
                url: '../../pages/index/index'
              });     
            }
          })
    },
  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    return util.share()
  }
})